package consultaADistancia;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.movil.registrodelapropiedadgt.PruebaWS1;
import com.movil.registrodelapropiedadgt.R;
import com.movil.registrodelapropiedadgt.PruebaWS1.conasync;
import com.movil.registrodelapropiedadgt.R.layout;
import com.movil.registrodelapropiedadgt.R.menu;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Finca extends Activity implements OnClickListener {
	
	private static final String SOAP_ACTION = "http://ejbs/DoctoTramite";
	private static final String METHOD_NAME = "DoctoTramite";
	private static final String NAMESPACE = "http://ejbs/";
	private static final String URL = "http://172.16.0.188:9080/ServiciosPublicosWeb/services/Movil?wsdl";
	
	final HttpTransportSE transporte = new HttpTransportSE(URL);
	
	conasync objcon =new conasync();
	
	
	Button BT_VerDocumento;
	EditText ET_NoFinca;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_finca);
		 
		//vitacora
  		BT_VerDocumento=(Button) findViewById(R.id.LBT_verDocuemento);
  		BT_VerDocumento.setOnClickListener(this);
  		
  		ET_NoFinca=(EditText) findViewById(R.id.LET_NoFinca);
  		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.finca, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) 
		{
		
			case R.id.LBT_verDocuemento:
				String STR_nofinca = ET_NoFinca.getText().toString();
				
				if(
						ET_NoFinca.getText().toString().equals("")
						||
						ET_NoFinca.getText().toString()==null
					)
				{
					Toast.makeText(
							getBaseContext(),
							"Debe de ingresar el numero de finca",
							Toast.LENGTH_LONG
							).show();
					 
				}
				else
				{
				
					objcon.execute("");
					Show_documentosEnTramite.NoDocumento=ET_NoFinca.getText().toString();
					Intent it_SDET = new Intent(this, Show_documentosEnTramite.class );
					startActivity(it_SDET);	
					
				}
			break;
			
		}
	}
	///////////////////////////////////////////////////////////////////////
	private ProgressDialog pd = null;

	public class conasync extends AsyncTask<String, String, String>  {
		
		public String IDDocumento="";
		@Override
		protected void onPreExecute() {
			pd = new ProgressDialog(Finca.this);
			pd.setTitle("Espere");
			pd.setMessage("Procesando, por favor espere....");
			pd.setCancelable(false);
			pd.setIndeterminate(true);
			pd.show();
			//pd.hide();
		}

		public SoapPrimitive resultString = null;

		protected void onPostExecute() {
			if (pd != null) {
				pd.dismiss();
				pd.hide();
			}
		}

		@Override
		protected String doInBackground(String... arg0) {
			// TODO Auto-generated method stub

			try {
				String STR_NoFinca=ET_NoFinca.getText().toString();
				
				//TV_WebServicews1.setText("Esperando respuesta");
				
				SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
				HttpTransportSE transporte = new HttpTransportSE(URL);
				Request.addProperty("propID","13R110502235");

				SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
						SoapEnvelope.VER11);
				//soapEnvelope.dotNet = true;
				soapEnvelope.setOutputSoapObject(Request);
				transporte.call(SOAP_ACTION, soapEnvelope);
				resultString = (SoapPrimitive) soapEnvelope.getResponse();
				System.out.println(resultString.toString());
				////////////////////////////
				Show_documentosEnTramite.Respuesta=resultString.toString();
				Show_documentosEnTramite.NoDocumento=ET_NoFinca.getText().toString();
				//Intent it_SDET = new Intent(this, Show_documentosEnTramite.class );
				//startActivity(it_SDET);
				/////////////////////////////////////////////////////////////////
				//TV_WebServicews1.setText(resultString.toString());
				pd.hide();
				//ET_NoFinca.setText("mensaje recibido");
				
			} catch (Exception e) {
				System.out.println("error en la conexion " + e.getMessage());

			}
			return null;
		}

		public void funcionCallback(String json) {

		}
	}
	///////////////////////////////////////////////////////////////////////

}
